﻿/*
	Class			Spot
	Package			utilities.Spot
	
	Description		Simplifies the code for externally loading a FLV file.
					Works just like Video class, but includes functions from NetStream Class.
					You can also access the NetStream object through the stream property.
					Also includes custom functions for resizing and centering the object in given dimensions.
					
	History			1.01	5/31/07		Added resize () and center () functions.
										Changed constructor to accept strings WIDESCREEN and STANDARD.
					1.00	5/30/07		Created
	
	To Do			Include all available functions of the NetStream class.
					Add custom functions as needed.
*/

package utilities
{
	import utilities.Stream;
	import flash.media.Video;
	
    public class Spot extends Video
    {
		public static const WIDESCREEN:String = "widescreen";
		public static const STANDARD:String   = "standard";
		public var stream:Stream;
		
        public function Spot (url:String, aspect:String = "standard")
        {
            stream = new Stream ();
			stream.bufferTime = 15;
			trace (stream.bufferTime);
			stream.play (url);
			
			var w:uint;
			switch (aspect)
			{
				case WIDESCREEN:
					w = 420;
					break;
				case STANDARD:
					w = 320;
					break;
				default:
					trace ("Error: Specified incorrect Aspect Ratio.");
			}
			
			super (w, 240);
			super.attachNetStream (stream);
        }
		
		
		public function resize (targetW:uint, targetH:uint):void
		{
			var scale:Number;
			var aspect:Number       = width / height;
			var targetAspect:Number = targetW / targetH;
			if (targetAspect < aspect)
			{
				scale = targetW / width;
			}
			else
			{
				scale = targetH / height;
			}
			
			scaleX = scaleY = scale;
		}
		
		
		public function center (containerWidth:uint, containerHeight:uint):void
		{
			var containerCenterX:Number = containerWidth / 2;
			var spotCenterX:Number      = width / 2;
			var containerCenterY:Number = containerHeight / 2;
			var spotCenterY:Number      = height / 2;
			
			var originX:uint            = Math.round (containerCenterX - spotCenterX);
			var originY:uint            = Math.round (containerCenterY - spotCenterY);
			
			x = originX;
			y = originY;
		}
		
		
		public function stop ():void
		{
			stream.pause ();
			stream.seek  (0);
		}
		
		
		public function pause ():void
		{
			stream.pause ();
		}
		
		
		public function resume ():void
		{
			stream.resume ();
		}
		

		public function togglePause ():void
		{
			stream.togglePause ();
		}
		
		
		public function seek (time:Number):void
		{
			stream.seek (time);
		}
		
    }
}

